from doc_loader import DocLoader
from dotenv import load_dotenv
import streamlit as st
import os
import torch

torch.classes.__path__ = [os.path.join(torch.__path__[0], torch.classes.__file__)]

# print(st.__path__)

load_dotenv()

doc = DocLoader()
# doc_list = doc.load_doc("G:\\开发工具\\books\\j2ee demo.pdf")
# doc.save_doc("G:\\开发工具\\books\\Books\\白话帛书周易.pdf")
# print("\n------")
# print(doc_list[0].page_content)
# print("\n------")
# print(doc_list[1].page_content)
# print("\n------")
# print(doc_list[2].page_content)
# print("\n------")
# print(doc_list[3].page_content)
# print("\n------")
# print(doc_list[4].page_content)
# print("\n------")
# print(doc_list[5].page_content)


# from FlagEmbedding import FlagModel
#
# model = FlagModel('BAAI/bge-m3',
#                                       query_instruction_for_retrieval="Represent this sentence for searching relevant passages:",
#                                       use_fp16=True)

# sentences_1 = ["I love NLP", "I love machine learning"]
# sentences_2 = ["I love BGE", "I love text retrieval"]
# embeddings_1 = model.encode(doc_list)
# embeddings_2 = model.encode(sentences_2)
# print(embeddings_1)
# print(embeddings_2)

import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger("char_doc_bot.get_doc").setLevel(logging.DEBUG)

# 设置页面标题
st.title("文档对话机器人--《白话帛书周易》")

# 问题1
q1 = st.text_area(
    "Q1: 请输入您想了解的内容",
    placeholder="例如：乾卦是什么意思？"
)

# 生成按钮
if st.button("发送"):
    # 检查是否所有问题都已回答
    if not all([q1]):
        st.warning("请先填写您想了解的内容")
    else:
        response = doc.get_doc(q1)
        # response = ""
        # for doc in res_docs:
        #     if doc is not None:
        #         response += doc.page_content + "\n"
        st.write(response.content)





# res_docs = doc.get_doc("兑卦是什么意思？")
# for doc in res_docs:
#     if doc is not None:
#         print(doc.page_content)

# print(len(res_docs))
